package com.ymatou.iapi.userservice.testcase;

import java.util.Date;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymatou.iapi.userservice.parameter.GLoginBillsRequestDtoBean;
import com.ymatou.iapi.userservice.parameter.UserBillsRequestDtoBean;
import com.ymatou.iapi.userservice.service.GLoginBillsRequestDtoCall;
import com.ymatou.iapi.userservice.service.GUserBillsRequestDtoCall;
import com.ymt.base.YmatouEasyCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.YmtUsers;
import com.ymttest.database.mongo.ULC201406Bean;
import com.ymttest.database.mongo.ULC201406Wapper;
import com.ymttest.database.sqlwapper.YmtUsersWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.BillsActionType;
import com.ymttest.utils.constant.ECode;

import sun.nio.cs.UnicodeEncoder;

/**
 * 修改登入凭据信息 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_GLoginBillsRequestDto {
	private static GLoginBillsRequestDtoBean gLoginBillsRequestDtoBean;
	private static GLoginBillsRequestDtoCall gLoginBillsRequestDtoCall;
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("用户信息确认请求接口");
	}

	@Before
	public void caseUp() throws Exception {
		gLoginBillsRequestDtoBean=new GLoginBillsRequestDtoBean();
		gLoginBillsRequestDtoCall=new GLoginBillsRequestDtoCall();
	}

	@AfterClass
	public static void tearDown() throws Throwable {
		Logger.generateResult(gLoginBillsRequestDtoCall.getOpurl()+"_GET");
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GLoginBillsRequestDto_001(){
		Logger.start(true, "GET查询信息LoginId已存在");
		try{
			UserRegisterInfoRequestDtoBean urb=JUserCallService.initUserRegisterInfoRequestDtoBean();
			JUserCallService.UserRegisterInfoRequestDtoCall(urb);
			gLoginBillsRequestDtoBean.setAction("12");
			gLoginBillsRequestDtoBean.setLoginId(urb.getLoginId());
			gLoginBillsRequestDtoCall.setData(gLoginBillsRequestDtoBean);
			gLoginBillsRequestDtoCall.callService();
			Logger.verifyEquals("400", gLoginBillsRequestDtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("false", gLoginBillsRequestDtoCall.getString("Success"), "验证操作成功");
			Logger.verifyIsContains("登录昵称已存在", gLoginBillsRequestDtoCall.getString("LastErrorMessage"), "验证Msg信息");
			Logger.verifyIsContains("\"Code\":\"LoginNameAleradExists\"", gLoginBillsRequestDtoCall.getString("Result"), "验证Resul信息");
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GLoginBillsRequestDto_002(){
		Logger.start(true, "GET查询信息moblie已存在");
		try{
			UserRegisterInfoRequestDtoBean urb=JUserCallService.initUserRegisterInfoRequestDtoBean();
			JUserCallService.UserRegisterInfoRequestDtoCall(urb);
			gLoginBillsRequestDtoBean.setAction("12");
			gLoginBillsRequestDtoBean.setMobile(urb.getLoginMobile());
			gLoginBillsRequestDtoCall.setData(gLoginBillsRequestDtoBean);
			gLoginBillsRequestDtoCall.callService();
			Logger.verifyEquals("400", gLoginBillsRequestDtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("false", gLoginBillsRequestDtoCall.getString("Success"), "验证操作成功");
			Logger.verifyIsContains("手机号码已存在", gLoginBillsRequestDtoCall.getString("LastErrorMessage"), "验证Msg信息");
			Logger.verifyIsContains("\"Code\":\"MobileAlreadyExists\"", gLoginBillsRequestDtoCall.getString("Result"), "验证Resul信息");
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GLoginBillsRequestDto_003(){
		Logger.start(true, "GET查询信息email已存在");
		try{
			UserRegisterInfoRequestDtoBean urb=JUserCallService.initUserRegisterInfoRequestDtoBean();
			urb.setLoginMail(TestDataManager.getEmail());
			JUserCallService.UserRegisterInfoRequestDtoCall(urb);
			gLoginBillsRequestDtoBean.setAction("12");
			gLoginBillsRequestDtoBean.setMail(urb.getLoginMail());
			gLoginBillsRequestDtoCall.setData(gLoginBillsRequestDtoBean);
			gLoginBillsRequestDtoCall.callService();
			Logger.verifyEquals("400", gLoginBillsRequestDtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("false", gLoginBillsRequestDtoCall.getString("Success"), "验证操作成功");
			Logger.verifyIsContains("邮箱地址已存在", gLoginBillsRequestDtoCall.getString("LastErrorMessage"), "验证Msg信息");
			Logger.verifyIsContains("\"Code\":\"EmailAlreadyExists\"", gLoginBillsRequestDtoCall.getString("Result"), "验证Resul信息");
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GLoginBillsRequestDto_004(){
		Logger.start(true, "GET查询信息uid和loginid匹配,成功");
		try{
			UserRegisterInfoRequestDtoBean urb=JUserCallService.initUserRegisterInfoRequestDtoBean();
			Integer uid = JUserCallService.UserRegisterInfoRequestDtoCall(urb).getUserid();
			gLoginBillsRequestDtoBean.setAction("12");
			gLoginBillsRequestDtoBean.setLoginId(urb.getLoginId());
			gLoginBillsRequestDtoBean.setUserId(uid.toString());
			gLoginBillsRequestDtoCall.setData(gLoginBillsRequestDtoBean);
			gLoginBillsRequestDtoCall.callService();
			Logger.verifyEquals("200", gLoginBillsRequestDtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", gLoginBillsRequestDtoCall.getString("Success"), "验证操作成功");
			Logger.verifyEquals("ok", gLoginBillsRequestDtoCall.getString("SuccessMessage"), "验证操作成功");
			Logger.verifyIsContains("\"Code\":\"Success\"", gLoginBillsRequestDtoCall.getString("Result"), "验证Resul信息");
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GLoginBillsRequestDto_005(){
		Logger.start(true, "GET查询信息uid和moblie匹配,成功");
		try{
			UserRegisterInfoRequestDtoBean urb=JUserCallService.initUserRegisterInfoRequestDtoBean();
			Integer uid = JUserCallService.UserRegisterInfoRequestDtoCall(urb).getUserid();
			gLoginBillsRequestDtoBean.setAction("12");
			gLoginBillsRequestDtoBean.setMobile(urb.getLoginMobile());
			gLoginBillsRequestDtoBean.setUserId(uid.toString());
			gLoginBillsRequestDtoCall.setData(gLoginBillsRequestDtoBean);
			gLoginBillsRequestDtoCall.callService();
			Logger.verifyEquals("200", gLoginBillsRequestDtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", gLoginBillsRequestDtoCall.getString("Success"), "验证操作成功");
			Logger.verifyEquals("ok", gLoginBillsRequestDtoCall.getString("SuccessMessage"), "验证操作成功");
			Logger.verifyIsContains("\"Code\":\"Success\"", gLoginBillsRequestDtoCall.getString("Result"), "验证Resul信息");
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GLoginBillsRequestDto_006(){
		Logger.start(true, "GET查询信息uid和email匹配,成功");
		try{
			UserRegisterInfoRequestDtoBean urb=JUserCallService.initUserRegisterInfoRequestDtoBean();
			urb.setLoginMail(TestDataManager.getEmail());
			Integer uid = JUserCallService.UserRegisterInfoRequestDtoCall(urb).getUserid();
			gLoginBillsRequestDtoBean.setAction("12");
			gLoginBillsRequestDtoBean.setMail(urb.getLoginMail());
			gLoginBillsRequestDtoBean.setUserId(uid.toString());
			gLoginBillsRequestDtoCall.setData(gLoginBillsRequestDtoBean);
			gLoginBillsRequestDtoCall.callService();
			Logger.verifyEquals("200", gLoginBillsRequestDtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", gLoginBillsRequestDtoCall.getString("Success"), "验证操作成功");
			Logger.verifyEquals("ok", gLoginBillsRequestDtoCall.getString("SuccessMessage"), "验证操作成功");
			Logger.verifyIsContains("\"Code\":\"Success\"", gLoginBillsRequestDtoCall.getString("Result"), "验证Resul信息");
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GLoginBillsRequestDto_007(){
		Logger.start(true, "GET查询信息uid和loginid不匹配,Code非SUCCESS(兼容net)");
		try{
			UserRegisterInfoRequestDtoBean urb=JUserCallService.initUserRegisterInfoRequestDtoBean();
			Integer uid = JUserCallService.UserRegisterInfoRequestDtoCall(urb).getUserid();
			gLoginBillsRequestDtoBean.setAction("12");
			gLoginBillsRequestDtoBean.setLoginId(urb.getLoginId()+1);
			gLoginBillsRequestDtoBean.setUserId(uid.toString());
			gLoginBillsRequestDtoCall.setData(gLoginBillsRequestDtoBean);
			gLoginBillsRequestDtoCall.callService();
			Logger.verifyEquals("200", gLoginBillsRequestDtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", gLoginBillsRequestDtoCall.getString("Success"), "验证操作成功");
			Logger.verifyIsContains("\"Code\":null", gLoginBillsRequestDtoCall.getString("Result"), "验证Resul信息");
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GLoginBillsRequestDto_008(){
		Logger.start(true, "GET查询信息uid和email不匹配,Code非SUCCESS(兼容net)");
		try{
			UserRegisterInfoRequestDtoBean urb=JUserCallService.initUserRegisterInfoRequestDtoBean();
			Integer uid = JUserCallService.UserRegisterInfoRequestDtoCall(urb).getUserid();
			gLoginBillsRequestDtoBean.setAction("12");
			gLoginBillsRequestDtoBean.setMail(urb.getLoginMail()+1);
			gLoginBillsRequestDtoBean.setUserId(uid.toString());
			gLoginBillsRequestDtoCall.setData(gLoginBillsRequestDtoBean);
			gLoginBillsRequestDtoCall.callService();
			Logger.verifyEquals("200", gLoginBillsRequestDtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", gLoginBillsRequestDtoCall.getString("Success"), "验证操作成功");
			Logger.verifyIsContains("\"Code\":null", gLoginBillsRequestDtoCall.getString("Result"), "验证Resul信息");
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GLoginBillsRequestDto_009(){
		Logger.start(true, "GET查询信息uid和mobile不匹配,Code非SUCCESS(兼容net)");
		try{
			UserRegisterInfoRequestDtoBean urb=JUserCallService.initUserRegisterInfoRequestDtoBean();
			Integer uid = JUserCallService.UserRegisterInfoRequestDtoCall(urb).getUserid();
			gLoginBillsRequestDtoBean.setAction("12");
			gLoginBillsRequestDtoBean.setMobile(urb.getLoginMobile()+1);
			gLoginBillsRequestDtoBean.setUserId(uid.toString());
			gLoginBillsRequestDtoCall.setData(gLoginBillsRequestDtoBean);
			gLoginBillsRequestDtoCall.callService();
			Logger.verifyEquals("200", gLoginBillsRequestDtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", gLoginBillsRequestDtoCall.getString("Success"), "验证操作成功");
			Logger.verifyIsContains("\"Code\":null", gLoginBillsRequestDtoCall.getString("Result"), "验证Resul信息");
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GLoginBillsRequestDto_010(){
		Logger.start(true, "GET查询信息LoginId不存在,成功");
		try{
			String loginId = "autotest_" + TestDataManager.randomStr(6);
			gLoginBillsRequestDtoBean.setAction("12");
			gLoginBillsRequestDtoBean.setLoginId(loginId);
			gLoginBillsRequestDtoCall.setData(gLoginBillsRequestDtoBean);
			gLoginBillsRequestDtoCall.callService();
			Logger.verifyEquals("200", gLoginBillsRequestDtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", gLoginBillsRequestDtoCall.getString("Success"), "验证操作成功");
			Logger.verifyEquals("ok", gLoginBillsRequestDtoCall.getString("SuccessMessage"), "验证操作成功");
			Logger.verifyIsContains("\"Code\":\"Success\"", gLoginBillsRequestDtoCall.getString("Result"), "验证Resul信息");
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GLoginBillsRequestDto_011(){
		Logger.start(true, "GET查询信息LoginMail不存在,成功");
		try{
			String loginId = "autotest_" + TestDataManager.randomStr(6);
			String loginMail = loginId + "@ymatou.com";
			gLoginBillsRequestDtoBean.setAction("12");
			gLoginBillsRequestDtoBean.setMail(loginMail);
			gLoginBillsRequestDtoCall.setData(gLoginBillsRequestDtoBean);
			gLoginBillsRequestDtoCall.callService();
			Logger.verifyEquals("200", gLoginBillsRequestDtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", gLoginBillsRequestDtoCall.getString("Success"), "验证操作成功");
			Logger.verifyEquals("ok", gLoginBillsRequestDtoCall.getString("SuccessMessage"), "验证操作成功");
			Logger.verifyIsContains("\"Code\":\"Success\"", gLoginBillsRequestDtoCall.getString("Result"), "验证Resul信息");
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GLoginBillsRequestDto_012(){
		Logger.start(true, "GET查询信息Loginmoblie不存在,成功");
		try{
			String moblie=TestDataManager.getPhoneNum();
			if(JUserCallService.mobileExists(moblie)){
				moblie=TestDataManager.getPhoneNum();
			}
			gLoginBillsRequestDtoBean.setAction("12");
			gLoginBillsRequestDtoBean.setMobile(moblie);
			gLoginBillsRequestDtoCall.setData(gLoginBillsRequestDtoBean);
			gLoginBillsRequestDtoCall.callService();
			Logger.verifyEquals("200", gLoginBillsRequestDtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", gLoginBillsRequestDtoCall.getString("Success"), "验证操作成功");
			Logger.verifyEquals("ok", gLoginBillsRequestDtoCall.getString("SuccessMessage"), "验证操作成功");
			Logger.verifyIsContains("\"Code\":\"Success\"", gLoginBillsRequestDtoCall.getString("Result"), "验证Resul信息");
		}catch(Exception e){
			Logger.fail(e);
		}
	}
//	http://userservice.ymatou.com/json/reply/LoginBillsRequestDto?Action=12&UserId=&LoginId=&Mail=&Mobile=13189718709
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_GLoginBillsRequestDto_013(){
		Logger.start(true, "GET查询信息,传入部分参数正确返回(修复前会404)");
		try{
			UserRegisterInfoRequestDtoBean urb=JUserCallService.initUserRegisterInfoRequestDtoBean();
			Integer uid = JUserCallService.UserRegisterInfoRequestDtoCall(urb).getUserid();
//			int userId = (Integer)user.get("userId");
			String url="http://userservice.iapi.ymatou.com/json/reply/LoginBillsRequestDto?Action=12&UserId=&LoginId=&Mail=&Mobile="+urb.getLoginMobile();
			YmatouEasyCall ec=new YmatouEasyCall(url, "GET", "PARAM");
			ec.callService();
			Logger.verifyEquals("400", ec.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("false", ec.getString("Success"), "验证操作成功");
			Logger.verifyIsContains("\"Code\":\"MobileAlreadyExists\"", ec.getString("Result"), "验证Resul信息");
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	//http://userservice.ymatou.com/json/reply/LoginBillsRequestDto?Mobile=jkcklnjn km mn n m&lkd8y9ty78uiuhdjhji&Action=12
	@Test
	@Category(P2.class)
	@TestCase
//	@Ignore
	public void Tc_GLoginBillsRequestDto_014(){
		Logger.start(true, "GET查询信息,传入带&字符异常报文不报错");
		try{
			String url="http://userservice.iapi.ymatou.com/json/reply/LoginBillsRequestDto?Action=12&Mobile=1&&1";
			YmatouEasyCall ec=new YmatouEasyCall(url, "GET", "PARAM");
			ec.callService();
			Logger.verifyEquals("200", ec.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", ec.getString("Success"), "验证操作成功");
		}catch(Exception e){
			Logger.fail(e);
		}
	}
}